package com.joplus.housekeeper.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;

import com.joplus.housekeeper.utils.L;

/**
 * Created by Administrator on 2016/8/18.
 */
public class AutoMiniHeightScroller extends ScrollView {

    String Tag = "AutoMiniHeightScroller";
    Context mcontext;

    public AutoMiniHeightScroller(Context context, AttributeSet attrs) {
        super(context, attrs);
        mcontext = context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        for (int i = 0; i < getChildCount(); i++) {
            View view = getChildAt(i);


            L.d(Tag,  MeasureSpec.getSize(heightMeasureSpec) + "  " + view.getHeight());
            if (i == 1||i==3) {
                if (view.getMeasuredHeight() < dip2px(mcontext, 180)) {
                    view.measure(widthMeasureSpec, dip2px(mcontext,180));
                } else {
                    super.onMeasure(widthMeasureSpec, dip2px(mcontext, view.getHeight()));
                }


            } else {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }


    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
